﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace Facebook_Authentication
{
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class MainWindow : Window
    {
        public MainWindow()
        {
            InitializeComponent();
        }

        private void btnGetAccessToken_Click(object sender, RoutedEventArgs e)
        {
            string redirectUrl = "http://www.facebook.com/connect/login_success.html";
            string caption = "Facebook OAuth Authentication";
            MessageBoxButton button = MessageBoxButton.OK;
            MessageBoxImage icon = MessageBoxImage.Warning;
            string message = "Please enter the {0}";

            if (String.IsNullOrWhiteSpace(txtAppId.Text))
            {
                MessageBox.Show(String.Format(message, "App ID"), caption, button, icon);
                return;
            }
            else if (String.IsNullOrWhiteSpace(txtScope.Text))
            {
                MessageBox.Show(String.Format(message, "scope permission(s)"), caption, button, icon);
                return;
            }

            FBAuthentication fbAuthenticate = new FBAuthentication(txtAppId.Text, redirectUrl, txtScope.Text);
            fbAuthenticate.ShowDialog();

            tbAccessToken.Text = fbAuthenticate.AccessToken;
            tbExpiresIn.Text = fbAuthenticate.ExpiresIn;
        }
    }
}
